/***********************************************************************
 * Module:  Topic.java
 * Author:  DAC
 * Purpose: Defines the Class Topic
 ***********************************************************************/
package com.group1.model;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

/** @pdOid a9a795f1-1d05-414d-9362-3e8f9a8e5b24 */
public class Topic {
   /** @pdOid ca7a33af-523a-4ccc-bf33-b0dbf9bc8e10 */
   protected void finalize() {
      // TODO: implement
   }
   
   /** @pdOid a0462df6-17a8-46cb-842d-6eb98e64d7f0 */
   public Integer topicId;
   /** @pdOid e09618ae-60de-4db1-b605-a1ffa5afd0ae */
   public java.lang.String topicName;
   /** @pdOid 73cce175-1f46-464b-9e4e-b0793fd5f35f */
   public java.lang.String topicNote;
   /** @pdOid bcdfc26c-5e1b-46d9-9667-48284ce05dff */
   public Integer topTopic;
   
   /** @pdRoleInfo migr=no name=Question assc=questionsInsideTopics coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<Question> question;
   /** @pdRoleInfo migr=no name=QuestionShortcut assc=shortcutsInsideOfTopics coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<QuestionShortcut> questionShortcut;
   /** @pdRoleInfo migr=no name=TopicShortcut assc=shortcutToTopics coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<TopicShortcut> topicShortcut2;
   /** @pdRoleInfo migr=no name=TopicShortcut assc=topicShortcutInsideATopic coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<TopicShortcut> topicShortcut;
   /** @pdRoleInfo migr=no name=Subject assc=topicsInsideOfSubject mult=0..1 side=A */
   public Subject subject;
   /** @pdRoleInfo migr=no name=Lecturer assc=creatorOfTopic mult=0..1 side=A */
   public Lecturer lecturer;
   
   /** @param topicID 
    * @param topicName 
    * @param topicNote 
    * @param topTopic 
    * @param subjectID 
    * @param lecturerID
    * @pdOid c3658731-d4fc-4cde-9320-44b0e1af654f */
   public Topic(Integer topicID, String topicName, String topicNote, Integer topTopic, String subjectID, String lecturerID) {
      this.topicId = topicID;
      this.topicName = topicName;
      this.topicNote = topicNote;
      this.topTopic = topTopic;
      this.subject.subjectId = subjectID;
      this.lecturer.lecturerId = lecturerID;
   }
   
   /** @param session
    * @pdOid 0e365c94-835d-4857-95f1-fa007ca01f51 */
   public static List<Topic> getAllTopic(Session session) {
     
	   Query query = session.createQuery("from Topic");                
	   List <Topic> listOfTopic = query.list();
	   return listOfTopic;
   }
   
   /** @param topicID 
    * @param session
    * @pdOid 4ed4e052-2eb2-457f-b220-25b49a2c78f9 */
   public static Topic getTopicByID(Integer topicID, Session session) {
      
      return (Topic) session.get(Topic.class, topicID);
   }
   
   /** @param subjectID 
    * @param session
    * @pdOid b8d75ff6-731f-4bd8-9e88-7be62a6e535f */
   public static List<Topic> getTopicBySubject(String subjectID, Session session) {
     
	   Query query = session.createQuery("from Topic where SUBJECT_ID = '" + subjectID + "'" );                
	   List <Topic> listOfTopic = query.list();
	   return listOfTopic;
   }
   
   /** @param lecturerId 
    * @param session
    * @pdOid e7f89987-d3dd-4eb7-b74b-d508c478e6bf */
   public static List<Topic> getTopicOfLecturer(String lecturerId, Session session) {
      
	   Query query = session.createQuery("from Topic where LECTURER_ID = '" + lecturerId + "'" );                
	   List <Topic> listOfTopic = query.list();
	   return listOfTopic;
   }
   
   /** @param topTopicID 
    * @param session
    * @pdOid 382171ab-d5bc-4980-be7e-0156fba475a8 */
   public static List<Topic> getTopicByTopTopic(int topTopicID, Session session) {
      
	   Query query = session.createQuery("from Topic where TOP_TOPIC_ID = '" + topTopicID + "'" );                
	   List <Topic> listOfTopic = query.list();
	   return listOfTopic;
   }
   
   /** @pdOid 5400390f-fb5a-44d1-9233-56eec2e8f2e7 */
   public Integer getTopicId() {
      return topicId;
   }
   
   /** @param newTopicId
    * @pdOid 952fc43d-4fff-4ee0-8b6b-5b1cd6da3309 */
   public void setTopicId(Integer newTopicId) {
      topicId = newTopicId;
   }
   
   /** @pdOid 5ddd0d56-c34a-4295-9634-46d65834a8f6 */
   public java.lang.String getTopicName() {
      return topicName;
   }
   
   /** @param newTopicName
    * @pdOid 4098dd6b-5cec-4ea9-83a0-6c03c423427f */
   public void setTopicName(java.lang.String newTopicName) {
      topicName = newTopicName;
   }
   
   /** @pdOid 91ccdaff-810b-4aec-8428-5cdbf1850473 */
   public java.lang.String getTopicNote() {
      return topicNote;
   }
   
   /** @param newTopicNote
    * @pdOid 8bdecbbe-269f-405c-a9f5-dc029478d01f */
   public void setTopicNote(java.lang.String newTopicNote) {
      topicNote = newTopicNote;
   }
   
   /** @pdOid 39b13dd4-0d37-45f6-8215-2979d4b82c70 */
   public Integer getTopTopic() {
      return topTopic;
   }
   
   /** @param newTopTopic
    * @pdOid be601026-f827-4a32-8fec-ddfe2361ce0f */
   public void setTopTopic(Integer newTopTopic) {
      topTopic = newTopTopic;
   }
   
   /** @pdOid 984b461f-bc18-41e6-b995-d7ef4d0e2ce6 */
   public Topic() {
      
   }
   
   
   /** @pdGenerated default getter */
   public java.util.Collection<Question> getQuestion() {
      if (question == null)
         question = new java.util.HashSet<Question>();
      return question;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorQuestion() {
      if (question == null)
         question = new java.util.HashSet<Question>();
      return question.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newQuestion */
   public void setQuestion(java.util.Collection<Question> newQuestion) {
      removeAllQuestion();
      for (java.util.Iterator iter = newQuestion.iterator(); iter.hasNext();)
         addQuestion((Question)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newQuestion */
   public void addQuestion(Question newQuestion) {
      if (newQuestion == null)
         return;
      if (this.question == null)
         this.question = new java.util.HashSet<Question>();
      if (!this.question.contains(newQuestion))
      {
         this.question.add(newQuestion);
         newQuestion.setTopic(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldQuestion */
   public void removeQuestion(Question oldQuestion) {
      if (oldQuestion == null)
         return;
      if (this.question != null)
         if (this.question.contains(oldQuestion))
         {
            this.question.remove(oldQuestion);
            oldQuestion.setTopic((Topic)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllQuestion() {
      if (question != null)
      {
         Question oldQuestion;
         for (java.util.Iterator iter = getIteratorQuestion(); iter.hasNext();)
         {
            oldQuestion = (Question)iter.next();
            iter.remove();
            oldQuestion.setTopic((Topic)null);
         }
      }
   }
   /** @pdGenerated default getter */
   public java.util.Collection<QuestionShortcut> getQuestionShortcut() {
      if (questionShortcut == null)
         questionShortcut = new java.util.HashSet<QuestionShortcut>();
      return questionShortcut;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorQuestionShortcut() {
      if (questionShortcut == null)
         questionShortcut = new java.util.HashSet<QuestionShortcut>();
      return questionShortcut.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newQuestionShortcut */
   public void setQuestionShortcut(java.util.Collection<QuestionShortcut> newQuestionShortcut) {
      removeAllQuestionShortcut();
      for (java.util.Iterator iter = newQuestionShortcut.iterator(); iter.hasNext();)
         addQuestionShortcut((QuestionShortcut)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newQuestionShortcut */
   public void addQuestionShortcut(QuestionShortcut newQuestionShortcut) {
      if (newQuestionShortcut == null)
         return;
      if (this.questionShortcut == null)
         this.questionShortcut = new java.util.HashSet<QuestionShortcut>();
      if (!this.questionShortcut.contains(newQuestionShortcut))
      {
         this.questionShortcut.add(newQuestionShortcut);
         newQuestionShortcut.setTopic(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldQuestionShortcut */
   public void removeQuestionShortcut(QuestionShortcut oldQuestionShortcut) {
      if (oldQuestionShortcut == null)
         return;
      if (this.questionShortcut != null)
         if (this.questionShortcut.contains(oldQuestionShortcut))
         {
            this.questionShortcut.remove(oldQuestionShortcut);
            oldQuestionShortcut.setTopic((Topic)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllQuestionShortcut() {
      if (questionShortcut != null)
      {
         QuestionShortcut oldQuestionShortcut;
         for (java.util.Iterator iter = getIteratorQuestionShortcut(); iter.hasNext();)
         {
            oldQuestionShortcut = (QuestionShortcut)iter.next();
            iter.remove();
            oldQuestionShortcut.setTopic((Topic)null);
         }
      }
   }
   /** @pdGenerated default getter */
   public java.util.Collection<TopicShortcut> getTopicShortcut2() {
      if (topicShortcut2 == null)
         topicShortcut2 = new java.util.HashSet<TopicShortcut>();
      return topicShortcut2;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorTopicShortcut2() {
      if (topicShortcut2 == null)
         topicShortcut2 = new java.util.HashSet<TopicShortcut>();
      return topicShortcut2.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newTopicShortcut2 */
   public void setTopicShortcut2(java.util.Collection<TopicShortcut> newTopicShortcut2) {
      removeAllTopicShortcut2();
      for (java.util.Iterator iter = newTopicShortcut2.iterator(); iter.hasNext();)
         addTopicShortcut2((TopicShortcut)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newTopicShortcut */
   public void addTopicShortcut2(TopicShortcut newTopicShortcut) {
      if (newTopicShortcut == null)
         return;
      if (this.topicShortcut2 == null)
         this.topicShortcut2 = new java.util.HashSet<TopicShortcut>();
      if (!this.topicShortcut2.contains(newTopicShortcut))
      {
         this.topicShortcut2.add(newTopicShortcut);
         newTopicShortcut.setTopic(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldTopicShortcut */
   public void removeTopicShortcut2(TopicShortcut oldTopicShortcut) {
      if (oldTopicShortcut == null)
         return;
      if (this.topicShortcut2 != null)
         if (this.topicShortcut2.contains(oldTopicShortcut))
         {
            this.topicShortcut2.remove(oldTopicShortcut);
            oldTopicShortcut.setTopic((Topic)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllTopicShortcut2() {
      if (topicShortcut2 != null)
      {
         TopicShortcut oldTopicShortcut;
         for (java.util.Iterator iter = getIteratorTopicShortcut2(); iter.hasNext();)
         {
            oldTopicShortcut = (TopicShortcut)iter.next();
            iter.remove();
            oldTopicShortcut.setTopic((Topic)null);
         }
      }
   }
   /** @pdGenerated default getter */
   public java.util.Collection<TopicShortcut> getTopicShortcut() {
      if (topicShortcut == null)
         topicShortcut = new java.util.HashSet<TopicShortcut>();
      return topicShortcut;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorTopicShortcut() {
      if (topicShortcut == null)
         topicShortcut = new java.util.HashSet<TopicShortcut>();
      return topicShortcut.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newTopicShortcut */
   public void setTopicShortcut(java.util.Collection<TopicShortcut> newTopicShortcut) {
      removeAllTopicShortcut();
      for (java.util.Iterator iter = newTopicShortcut.iterator(); iter.hasNext();)
         addTopicShortcut((TopicShortcut)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newTopicShortcut */
   public void addTopicShortcut(TopicShortcut newTopicShortcut) {
      if (newTopicShortcut == null)
         return;
      if (this.topicShortcut == null)
         this.topicShortcut = new java.util.HashSet<TopicShortcut>();
      if (!this.topicShortcut.contains(newTopicShortcut))
      {
         this.topicShortcut.add(newTopicShortcut);
         newTopicShortcut.setTopTopic(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldTopicShortcut */
   public void removeTopicShortcut(TopicShortcut oldTopicShortcut) {
      if (oldTopicShortcut == null)
         return;
      if (this.topicShortcut != null)
         if (this.topicShortcut.contains(oldTopicShortcut))
         {
            this.topicShortcut.remove(oldTopicShortcut);
            oldTopicShortcut.setTopTopic((Topic)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllTopicShortcut() {
      if (topicShortcut != null)
      {
         TopicShortcut oldTopicShortcut;
         for (java.util.Iterator iter = getIteratorTopicShortcut(); iter.hasNext();)
         {
            oldTopicShortcut = (TopicShortcut)iter.next();
            iter.remove();
            oldTopicShortcut.setTopTopic((Topic)null);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public Subject getSubject() {
      return subject;
   }
   
   /** @pdGenerated default parent setter
     * @param newSubject */
   public void setSubject(Subject newSubject) {
      if (this.subject == null || !this.subject.equals(newSubject))
      {
         if (this.subject != null)
         {
            Subject oldSubject = this.subject;
            this.subject = null;
            oldSubject.removeTopic(this);
         }
         if (newSubject != null)
         {
            this.subject = newSubject;
            this.subject.addTopic(this);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public Lecturer getLecturer() {
      return lecturer;
   }
   
   /** @pdGenerated default parent setter
     * @param newLecturer */
   public void setLecturer(Lecturer newLecturer) {
      if (this.lecturer == null || !this.lecturer.equals(newLecturer))
      {
         if (this.lecturer != null)
         {
            Lecturer oldLecturer = this.lecturer;
            this.lecturer = null;
            oldLecturer.removeTopic(this);
         }
         if (newLecturer != null)
         {
            this.lecturer = newLecturer;
            this.lecturer.addTopic(this);
         }
      }
     
    	//  this.lecturer = newLecturer;

      
   }

}